package com.gome.security.util.ECDSA;

import java.util.Map;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;

import com.gome.security.util.DSA.DSACoder;
import com.gome.security.util.DSA.DSACoderTest;

public class ECDSACoderTest {

	// 公钥
		private static byte[] publicKey;
		// 私钥
		private static byte[] privateKey;

		/**
		 * 初始化密钥
		 * 
		 * @throws Exception
		 */

		public void initKey() throws Exception {

			Map<String, Object> keyMap = ECDSACoder.initKey();
			publicKey = ECDSACoder.getPublicKey(keyMap);
			privateKey = ECDSACoder.getPrivateKey(keyMap);
			System.out.println("公钥: \n" + Base64.encodeBase64String(publicKey));
			System.out.println("私钥: \n" + Base64.encodeBase64String(privateKey));

		}

		public static void main(String str[]) throws Exception {
			String inputstr = "ECDSA数字签名";
			byte[] data = inputstr.getBytes();
			ECDSACoderTest dct = new ECDSACoderTest();
			dct.initKey();
			
			byte[] sign = ECDSACoder.sign(data, privateKey);
			System.out.println("签名: \n" + Hex.encodeHexString(sign));

			boolean status = ECDSACoder.verify(data, publicKey, sign);
			System.out.println("签名验证: \n" + status);

		}

}
